package cn.tao.org.controller;



import cn.tao.org.domain.Department;
import cn.tao.org.domain.Systemdictionarytype;
import cn.tao.org.query.EmployeeQuery;
import cn.tao.org.query.SystemdictionarytypeQuery;
import cn.tao.org.service.IShopService;
import cn.tao.org.service.ISystemdictionarytypeService;
import cn.tao.utils.AjaxResult;
import cn.tao.utils.QueryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemdictionarytype")
public class SystemdictionarytypeController {

    @Autowired
    private ISystemdictionarytypeService systemdictionarytypeService;

    /**
     * 新增和修改
     * @RequestBody 接收一个json类型的对象
     * @param systemdictionarytype
     * @return
     */
    @PutMapping
    public AjaxResult savAndUpt(@RequestBody Systemdictionarytype systemdictionarytype){
        try {
            if (systemdictionarytype.getId() == null){
                systemdictionarytypeService.save(systemdictionarytype);
            }else {
                systemdictionarytypeService.update(systemdictionarytype);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }

    /**
     *("/{id}"):要与@PathVariable中的参数对应
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult delById(@PathVariable("id") Long id){
        try{
            systemdictionarytypeService.delete(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }

    /**
     * 根据id查询一个
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Systemdictionarytype findEmployeeById(@PathVariable("id") Long id){
        return systemdictionarytypeService.loadById(id);
    }



    /**
     * 查询所有
     * @return
     */
    @GetMapping
    public List<Systemdictionarytype> findEmployees(){
       return systemdictionarytypeService.loadAll();
    }


    /**
     * 高级查询和分页
     * @param query
     * @return
     */
    @PostMapping
    public QueryResult<Systemdictionarytype> findEmployeeByQuery(@RequestBody SystemdictionarytypeQuery query){

        return systemdictionarytypeService.findByQuery(query);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PatchMapping
    public AjaxResult batchDelete(@RequestBody Long[] ids){
        try {
            systemdictionarytypeService.batchDelete(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }

    /**
     *
     * @return
     */
    @GetMapping("/loadTree")
    public List<Systemdictionarytype> findDictionTree(){
        return systemdictionarytypeService.findDictionTree();

    }


}
